﻿@{
    Layout = "~/Views/Shared/Modern.cshtml";
}
@{

    var colors = new string[]{
                "bg-color-blue",
                "bg-color-blueDark",
                "bg-color-green",
                "bg-color-greenDark",
                "bg-color-red",
                "bg-color-orange",
                "bg-color-pink",
                "bg-color-purple",
};

    Random random = new Random();
}
@{
    var functioncontainer = 0;
}
<div id="functioncontainer" style="display:none">
    <div id="functioncontainerinner">
        @foreach (LineOfBusiness.Poco.SYS_FunctionList func in ViewBag.FunctionGroup)
        {

            var w = ((IList<LineOfBusiness.Poco.SYS_FunctionList>)ViewBag.FunctionItem).Where(o => o.ParentID == func.FunctionID).Count();
            var w1 = (((w / 4) + 1) * 130);
            functioncontainer = functioncontainer + w1;
            <div class="FunctionGroup" style="width:@w1.ToString()px" id="FunctionGroup_@func.FunctionID">
                <div class="FunctionGroupItem" id="@func.FunctionID">
                    <span class="moduletext">@func.CustomName.ToUpper()</span>
                </div>

                <div class="content" id="content_@func.FunctionID">
                    @foreach (var item in ((IList<LineOfBusiness.Poco.SYS_FunctionList>)ViewBag.FunctionItem).Where(o => o.ParentID == func.FunctionID))
                    {
                        <div class="FunctionItemItem  @colors[random.Next(0, 7)]" id="@item.FunctionID">
                            <div class="FunctionItemItemtext">@item.CustomName</div>
                        </div>

                    }
                </div>
            </div>


        }
    </div>
</div>

<script type="text/javascript">
     $("#functioncontainerinner").width(@functioncontainer + 300);
</script>

<script type="text/javascript">
        @{
            MvcHtmlString sJSON = null;
            Newtonsoft.Json.JsonSerializerSettings ss = new Newtonsoft.Json.JsonSerializerSettings();
            ss.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
            ss.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            ss.ContractResolver = new LineOfBusiness.Core.Utilities.TopLevelContractResolver();

            sJSON = MvcHtmlString.Create(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.FunctionItem, ss) as string);
        }

    var modelview = [  @sJSON];
    window.onunload = function () {
        $("#ModernBusy").hide();
    }
    $(document).ready(function () {
        resize();

        $("#functioncontainer").on("mousewheel", function (event, delta, deltaX, deltaY) {
            $('#functioncontainer').scrollLeft($('#functioncontainer').scrollLeft() + delta * 50);
        });

        $("#functioncontainer")
       .css({
           'margin-left': 20,
           'opacity': 0,
       })
       .show()
       .animate({
           'margin-left': 0,
           'opacity': 1
       }, 500, 'swing')

        $(".FunctionItemItem").click(function () {
            var funtion = null;
            if (modelview != null && modelview.length > 0)
                for (var i = 0; i < modelview[0].length; i++) {
                    if (modelview[0][i].FunctionID == this.id || ("all_" + modelview[0][i].FunctionID == this.id)) {
                        funtion = modelview[0][i];
                        break;
                    }
                }

            if (funtion != null) {
                SelectFunction(funtion);
            }
        });
    });

    window.onresize = function () {
        resize();
    }

    function resize()
    {
        $("#functioncontainer").width($(window).width() - 10);
        $("#functioncontainer").height($(window).height() - 125);
        $("#functioncontainerinner").css("margin-top", ($("#functioncontainer").height() - 520) / 2);
    }
    function SelectFunction(model) {
        var nametab = "";

        var url = "@Html.BaseUrl()" + model.Url;
        _SelectFunction(model, url);
    }

    function _SelectFunction(model, url, nametab) {
            nametab = nametab || "";
            if (IsNullOrEmty(url)) return;

            var per = PostServer('@Url.Action("GetExecPer", "Shared")?type=1&functionID=' + model.FunctionID);

            if (!per.Active) {
                ShowMessage('AccNet i', 'YouNotPermission', 'You not permission for this function.', null, null, 'OK');
                return
            }

            if (model.DisplayMode == "1") {
                for (i = 0; i < managewindow.length; i++) {
                    if (managewindow[i].name == model.id + nametab) {
                        managewindow[i].restore();
                        managewindow[i].toFront();
                        return;
                    }
                }
                OpenForm(url, model.Width, model.Height, '1', model.CustomName, true, model.id + nametab);
            }
            else if (model.DisplayMode == "2") {
                window.open(url);
            }
            else {
                if (url != "" && url != null) {
                    $("#ModernBusy").show();
                    setTimeout(function () { document.location.href = url; }, 10);

                }
            }
    }
</script>